package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageResult page(Integer page, Integer pageSize) {
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);

        //2.执行查询
        Page<Student> pageInfo = studentMapper.list();

        //3.封装结果
        return new PageResult(pageInfo.getTotal(), pageInfo.getResult());
    }

    @Override
    public void save(Student student) {
        studentMapper.save(student);
    }

    @Override
    public Student getById(Integer id) {
        Student student = studentMapper.getById(id);
        return student;
    }

    @Override
    public void update(Student student) {
        studentMapper.update(student);
    }

    @Override
    public void deleteById(List<Integer> ids) {
        studentMapper.deleteById(ids);
    }

    @Override
    public Integer getViolationCount(Integer id) {
        return studentMapper.getViolationCount(id);
    }

    @Override
    public void addViolation(Integer id, Integer newCount, Integer score) {
        studentMapper.addViolation(id,newCount,score);
    }


}
